using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entities;
using Utility;

namespace BUS
{
    public class tbDanhmucBUS
    {
        public static void Insert(tbDanhmuc dm)
        {
            tbDanhmucDAL dmDAL = new tbDanhmucDAL();
            dmDAL.Insert(dm);
        }
        public static void Update(tbDanhmuc dm)
        {
            tbDanhmucDAL dmDAL = new tbDanhmucDAL();
            dmDAL.Update(dm);
        }
        public static void Delete(int iD)
        {
            tbDanhmucDAL dmDAL = new tbDanhmucDAL();
            dmDAL.Delete(iD);
        }
        public static tbDanhmucCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbDanhmucDAL dmDAL = new tbDanhmucDAL();
            return dmDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbDanhmucCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDanhmucDAL dmDAL = new tbDanhmucDAL();
            return dmDAL.Get(cri.Criter, 0, 0, tbDanhmucColumn.Madanhm.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbDanhmuc GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbDanhmucColumn.Madanhm.ToString(), Condition.EQUAL, iD);
            tbDanhmucDAL dmDAL = new tbDanhmucDAL();
            tbDanhmucCollection tbdanhmucCollection = dmDAL.Get(cri.Criter, 0, 0, tbDanhmucColumn.Madanhm.ToString(), OrderDirection.ASC.ToString(), out total);
            if (tbdanhmucCollection.Count > 0)
                return tbdanhmucCollection[0];
            return null;
        }
        public static tbDanhmucCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDanhmucDAL dmDAL = new tbDanhmucDAL();
            return dmDAL.Get(cri.Criter, 1, number,
             tbDanhmucColumn.Madanhm.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbDanhmucCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDanhmucDAL dmDAL = new tbDanhmucDAL();
            return dmDAL.Get(cri.Criter, 1, number,
               tbDanhmucColumn.Madanhm.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
